eliminate weird input mode of gpx reader.
authortsteven4 <tsteven4@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 23 Aug 2013 23:10:51 +0000 (23:10 +0000)
committertsteven4 <tsteven4@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 23 Aug 2013 23:10:51 +0000 (23:10 +0000)
add a test to make sure standard input works.

git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4561 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/gpx.cc
gpsbabel/testo.d/gpx.test

index 2421c0824671e18e058671f3ee223a9f9ee1890a..b9aa5818be99f9bdd5110552b961ba4f9dfdd63c 100644 (file)
@@ -53,15 +53,12 @@ static waypoint* wpt_tmp;
 static UrlLink* link_;
 static int cache_descr_is_html;
 static gbfile* fd;
-static const char* input_fname;
 static gpsbabel::File* oqfile;
 static gpsbabel::XmlStreamWriter* writer;
 static short_handle mkshort_handle;
 static const char* link_url = NULL;
 static const char* link_text = NULL;
 
-static const char* input_string = NULL;
-static int input_string_len = 0;
 
 static char* snlen = NULL;
 static char* suppresswhite = NULL;
@@ -1290,16 +1287,7 @@ gpx_cdata(void* dta, const XML_Char* xml_el, int len)
 static void
 gpx_rd_init(const char* fname)
 {
-  if (fname[0]) {
-    fd = gbfopen(fname, "r", MYNAME);
-    input_fname = fname;
-  } else {
-    fd = NULL;
-    input_string = fname+1;
-    input_string_len = strlen(input_string);
-    input_fname = NULL;
-  }
-
+  fd = gbfopen(fname, "r", MYNAME);
 
   current_tag.clear();
 
@@ -1343,7 +1331,6 @@ gpx_rd_deinit(void)
   psr = NULL;
   wpt_tmp = NULL;
   cur_tag = NULL;
-  input_fname = NULL;
 }
 #endif
 
@@ -1378,28 +1365,12 @@ gpx_read(void)
 {
 #if HAVE_LIBEXPAT
   int len;
-  int done = 0;
   char* buf = (char*) xmalloc(MY_CBUF_SZ);
-  int result = 0;
-
-  while (!done) {
-    if (fd) {
-      len = gbfread(buf, 1, MY_CBUF_SZ - 1, fd);
-      done = gbfeof(fd) || !len;
-      result = XML_Parse(psr, buf, len, done);
-    } else if (input_string) {
-      done = 0;
-      result = XML_Parse(psr, input_string,
-                         input_string_len, done);
-      done = 1;
-    } else {
-      done = 1;
-      result = -1;
-    }
-    if (!result) {
-      fatal(MYNAME ": XML parse error at line %d of '%s' : %s\n",
+
+  while ((len = gbfread(buf, 1, MY_CBUF_SZ - 1, fd))) {
+    if (!XML_Parse(psr, buf, len, gbfeof(fd))) {
+      fatal(MYNAME ":Parse error at %d: %s\n",
             (int) XML_GetCurrentLineNumber(psr),
-            input_fname ? input_fname : "unknown file",
             XML_ErrorString(XML_GetErrorCode(psr)));
     }
   }
index 85d29e943a8456ea0cbfd6ff12d6268ced9e24a5..9624467501fa8095ea0da5b32903404d973f5939 100644 (file)
@@ -30,3 +30,8 @@ compare ${REFERENCE}/bigtime.gpx ${TMPDIR}/bigtime.gpx
 rm -f ${TMPDIR}/basecamp~gpx_so.gpx
 gpsbabel -i gpx -f ${REFERENCE}/basecamp.gpx -o gpx -F - 1> ${TMPDIR}/basecamp~gpx_so.gpx
 compare ${REFERENCE}/basecamp~gpx.gpx ${TMPDIR}/basecamp~gpx_so.gpx 
+
+# test standard input
+rm -f ${TMPDIR}/basecamp~gpx_si.gpx
+gpsbabel -i gpx -f - -o gpx -F ${TMPDIR}/basecamp~gpx_si.gpx 0< ${REFERENCE}/basecamp.gpx
+compare ${REFERENCE}/basecamp~gpx.gpx ${TMPDIR}/basecamp~gpx_si.gpx